package org.java.mathgame.screens;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.scenes.scene2d.EventListener;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.InputListener;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import org.java.mathgame.MathGame;

import javax.microedition.khronos.opengles.GL10;

public class MainMenuScreen implements Screen {
    private MathGame game;
    private SpriteBatch spriteBatch;
    private BitmapFont font, buttFont;
    private Stage stage;
    private Table table;
    private Skin skin;
   private  TextButton startGameButton, optionsButton, howToPlayButton;
    private TextureAtlas atlas;
    private BitmapFont black, white;


    // constructor to keep a reference to the main Game class
    public MainMenuScreen(final MathGame game){

        this.game = game;



        //Skin skin = new Skin();
// 100% width and 100% height on the table (fills the stage)
        Stage stage = new Stage();
        Table table = new Table();
       table.setFillParent(true);
// add the table to the stage
         stage.addActor(table);
         TextButton.TextButtonStyle style = new TextButton.TextButtonStyle();
         style.font = new BitmapFont();
         //register the button "start game"
         startGameButton = new TextButton("Start game", style);
          startGameButton.addListener(new InputListener() {

            @Override
             protected void touchUp(
                    EventListener event,
                    float x,
                    float y,
                     int pointer,
                    int button) {
                touchUp(event, x, y, pointer, button);

                game.setScreen(new GameScreen(game));
           }
      });
           table.add(startGameButton).size(300, 60).uniform().spaceBottom(10);
        table.row();

        // register the button "options"
        optionsButton = new TextButton("Game Settings", style);
        optionsButton.addListener(new InputListener() {
            @Override
            public void touchUp(
                    InputEvent event,
                    float x,
                    float y,
                    int pointer,
                    int button) {
                touchUp(event, x, y, pointer, button);
                game.setScreen(new GameSettingsScreen(game));
            }
        });
        table.add(optionsButton).uniform().fill().spaceBottom(10);
        table.row();

        howToPlayButton = new TextButton("How to Play", style);
        howToPlayButton.addListener(new InputListener() {
            @Override
            public void touchUp(
                    InputEvent event,
                    float x,
                    float y,
                    int pointer,
                    int button) {
                touchUp(event, x, y, pointer, button);
                game.setScreen(new HowToPlayScreen(game));
            }
        });
        table.add(howToPlayButton).uniform().fill().spaceBottom(10);
        table.row();

    }


      @Override
    public void render(float delta) {
          Gdx.gl.glClearColor(0.5f, 0.3f, 0.6f, 1);
          Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
          stage.act(delta);

stage.draw();


      }

    @Override
    public void resize(int width, int height) {
        if(stage == null)
            stage = new Stage(width, height, true);
        stage.clear();



    }

    @Override
    public void show() {

    }

    @Override
    public void hide() {
        // called when current screen changes from this to a different screen
    }


    @Override
    public void pause() {
    }


    @Override
    public void resume() {
    }


    @Override
    public void dispose() {
        // never called automatically
    }
}
